﻿#include "stdafx.h"
#include "C_FieldProbe.h"


/*
-----==========================================================-----
		类：		场强探头 数据类.h
		作者：		drill_up
		所属模块：	场强探头模块
		功能：		场强探头模块的数据类对象
-----==========================================================-----
*/

C_FieldProbe::C_FieldProbe() : C_UndoDataBase() {

	// > 属性
	this->name = "";				//监视器名称，会依据参数自动生成

	// > 数据
	this->m_FieldType = 0;		
	this->m_OrientationType = 3;	//方向 (0:X, 1:Y, 2:Z, 3:All(X, Y, Z, Abs)
	this->m_PosX = 0.0;
	this->m_PosY = 0.0;
	this->m_PosZ = 0.0;

	// > UI参数
	this->m_autoCheck = true;
}

C_FieldProbe::~C_FieldProbe() {
}


/*-------------------------------------------------
		属性 - 设置名称
*/
void C_FieldProbe::setName(QString name) {
	this->name = name;
}
/*-------------------------------------------------
		属性 - 获取名称
*/
QString C_FieldProbe::getName() {
	return this->name;
}

/*-------------------------------------------------
		参数 - 从字符串返回类型下标
*/
int C_FieldProbe::getFieldTypeByStr(const QString &typeStr)
{
	QStringList list = {"efield", "hfield", "efarfield", "hfarfield", "rcs"};
	int retIndex = list.indexOf(typeStr.toLower());
	if (retIndex == -1){
		return 0;
	}
	return retIndex;
}

/*-------------------------------------------------
		参数 - 从字符串返回方向下标
*/
int C_FieldProbe::getOrientationByStr(const QString &typeStr)
{
	QStringList list = {"x", "y", "z", "all"};
	int retIndex = list.indexOf(typeStr.toLower());
	if (retIndex == -1){
		return 3;
	}
	return retIndex;
}

/*-------------------------------------------------
		参数 - 下拉框参数
*/
QStringList C_FieldProbe::getFieldItems()
{
	QStringList fields;
	fields << "E-Field" << "H-Field" << "E-Field(Farfield)" << "H-Field(Farfield)" << "RCS";
	return fields;
}

/*-------------------------------------------------
		描述 - 获取求解器用文本
*/
QString C_FieldProbe::getFieldType_solverString() {
	if (this->m_FieldType == 0){
		// 处理E-field情况
		return "E_field";
	}
	else if (this->m_FieldType == 1){
		// 处理H-field情况
		return "H_field";
	}
	else if (this->m_FieldType == 2){
		// 处理E-field(Farfield)情况
		return "E_field(Farfield)";
	}
	else if (this->m_FieldType == 3){
		// 处理H-field(Farfield)情况
		return "H_field(Farfield)";
	}
	else if (this->m_FieldType == 4){
		// 处理RCS情况
		return "RCS";
	}else {
		return "error index";
	}
}

/*-------------------------------------------------
		描述 - 获取属性描述
*/
QPair<QString, QString> C_FieldProbe::getAttributesDesc() {
	QPair<QString, QString> context_pair;

	context_pair.first.append(QObject::tr("Type"));
	context_pair.first.append("\n");
	context_pair.second.append("= ");
	context_pair.second.append(this->getFieldItems().at(this->m_FieldType));
	context_pair.second.append("\n");

	context_pair.first.append(QObject::tr("Position"));
	context_pair.first.append("\n");
	context_pair.second.append("= ");
	context_pair.second.append("(");
	context_pair.second.append(QString::number(this->m_PosX));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->m_PosY));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->m_PosZ));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	return context_pair;
}


/*-------------------------------------------------
		访问器 - 获取子类类名
*/
QString C_FieldProbe::get__CLASS_NAME__() {
	return "C_FieldProbe";
}
/*-------------------------------------------------
		访问器 - 获取子类类名（中文名）
*/
QString C_FieldProbe::get__CLASS_NAME__Chinese() {
	return "场强探头";
}
/*-------------------------------------------------
		访问器 - 获取所有继承的类名
*/
QStringList C_FieldProbe::get__CLASS_INHERITED_LIST__(){
	return C_UndoDataBase::get__CLASS_INHERITED_LIST__() << "C_FieldProbe";
}
/*-------------------------------------------------
		访问器 - 是否继承了某类
*/
bool C_FieldProbe::get__CLASS_IS_INSTANCE_OF__(QString class_name){
	return this->get__CLASS_INHERITED_LIST__().contains(class_name);
}
/*-------------------------------------------------
		访问器 - 原型复制对象
*/
C_FieldProbe C_FieldProbe::clone() {
	return C_FieldProbe(*this);
}
QSharedPointer<C_FieldProbe> C_FieldProbe::clonePtr() {
	return QSharedPointer<C_FieldProbe>(new C_FieldProbe(*this));
}
C_UndoDataBasePtr C_FieldProbe::cloneParentPtr() {
	return this->clonePtr();
}

/*-------------------------------------------------
		复制对象
*/
void C_FieldProbe::copyFrom(C_FieldProbe* a) {

	// > 属性
	this->name = a->name;

	// > 数据
	this->m_FieldType = a->m_FieldType;
	this->m_OrientationType = 3;
	this->m_PosX = 0.0;
	this->m_PosY = 0.0;
	this->m_PosZ = 0.0;

	// > UI参数
	this->m_autoCheck = true;
}
/*-------------------------------------------------
		运算符重载
*/
const bool C_FieldProbe::operator== (const C_FieldProbe& a)const {
	return C_UndoDataBase::operator==(a);
}
/*-------------------------------------------------
		空判断
*/
bool C_FieldProbe::isNull() {
	return C_UndoDataBase::isNull();
}

/*-------------------------------------------------
		实体类 -> QJsonObject
*/
QJsonObject C_FieldProbe::getJsonObject_undoChildData() {
	QJsonObject obj;

	// > 属性
	obj.insert("name", this->name);

	// > 数据
	obj.insert("portType", this->m_FieldType);
	obj.insert("orientationType", this->m_OrientationType);
	obj.insert("posX", this->m_PosX);
	obj.insert("posY", this->m_PosY);
	obj.insert("posZ", this->m_PosZ);

	// > UI参数
	obj.insert("autoCheck", this->m_autoCheck);

	return obj;
}
/*-------------------------------------------------
		QJsonObject -> 实体类
*/
void C_FieldProbe::setJsonObject_undoChildData(QJsonObject obj) {

	// > 属性
	this->name = obj.value("name").toString();

	// > 数据
	this->m_FieldType = obj.value("portType").toInt();
	this->m_OrientationType = obj.value("orientationType").toInt();
	this->m_PosX = obj.value("posX").toDouble();
	this->m_PosY = obj.value("posY").toDouble();
	this->m_PosZ = obj.value("posZ").toDouble();

	// > UI参数
	this->m_autoCheck = obj.value("autoCheck").toBool();
}

